package com.xpd.spring.jdbc;

import com.xpd.spring.jdbc.bean.Account;
import com.xpd.spring.jdbc.biz.BankBiz;
import com.xpd.spring.jdbc.dao.AccountDao;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@ContextConfiguration(classes = JdbcConfig.class)
public class JdbcText {
    @Autowired
    AccountDao accountDao;

    @Test
    public void test(){
        Account account=new Account();
        account.setId(22435931);
        account.setPassword("123");
        account.setBalance(1000.00);
        accountDao.insert(account);
        Account account1 = accountDao.selectByid(account.getId());
        System.out.println("account1 = " + account1);
        account.setBalance(20000.00);
        accountDao.updateByid(account);
        Account account2 = accountDao.selectByid(account.getId());
        System.out.println("account2 = " + account2);
        List<Account> accounts = accountDao.selectAll();
        for (int i = 0; i < accounts.size(); i++) {
            System.out.println("accounts = " + accounts.get(i));
        }
    }
    @Autowired
    BankBiz bankBiz;
    @Test
    public void text1(){
        Account account = accountDao.selectByid(1);
        System.out.println(account);
        bankBiz.deposit(1,1000.0);
        Account account1 = accountDao.selectByid(1);
        System.out.println(account1);
    }
}
